package com.example.intenttrial;

import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

public class NetworkingActivity extends Activity {

	private RequestQueue queue;
	
	private EditText input;
	private TextView output;
	private Button send;
	private Button cancel;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.screen_networking);
		
		mapUI();
	}

	@Override
	protected void onResume() {
		super.onResume();
		
		queue = Volley.newRequestQueue(this);
	}

	private void mapUI() {
		input = (EditText) findViewById(R.id.edtxt_input);
		output = (TextView) findViewById(R.id.tv_output);
		send = (Button) findViewById(R.id.btn_send);
		cancel = (Button) findViewById(R.id.btn_cancel);
		
		send.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				sendRequest();
			}
		});
	}
	
	private void sendRequest() {
		
		
		String url = "http://www.google.com.ua/";

		StringRequest request = new StringRequest(url, new Response.Listener<String>() {
			
			@Override
			public void onResponse(String response) {
				output.setText("Response => " + response.toString());
			}
		}, 
		new Response.ErrorListener() {
			@Override
			public void onErrorResponse(VolleyError error) {
				
			}
			
		});
		
		queue.add(request);
	}

}
